# CalBMIv4.py

def get_input():
    while True:
        user_input = input("输入身高(米)和体重(公斤)[逗号隔开]：")
        try:
            # 尝试将输入分割并转换为浮点数
            height, weight = map(float, user_input.split(','))
            return height, weight
        except ValueError:
            # 如果转换失败，提示用户重新输入
            print("输入内容必须为数字，请重新输入。")


def calculate_bmi(height, weight):
    # 计算BMI值
    return weight / (height ** 2)


def determine_health_status(bmi):
    # 根据BMI值确定健康状况
    if bmi < 18.5:
        return "偏瘦", "偏瘦"
    elif bmi < 25:
        return "正常", "正常"
    elif bmi < 28:
        return "偏胖", "偏胖"
    else:
        return "肥胖", "肥胖"


def main():
    while True:
        # 获取用户输入
        height, weight = get_input()

        # 计算BMI
        bmi = calculate_bmi(height, weight)

        # 输出BMI值
        print("BMI 数值为：{:.2f}".format(bmi))

        # 确定健康状况
        who, nat = determine_health_status(bmi)
        print(f"BMI 指标为：国际'{who}', 国内'{nat}'")

        # 询问用户是否继续
        if input("是否继续程序? (y/n): ").lower() != 'y':
            print("谢谢使用BMI计算程序。")
            break


if __name__ == "__main__":
    try:
        main()
    except Exception as e:
        print(f"程序出现异常：{e}")